package de.hsb.ai.agent.misterx.brain.geoanalyser;

public class CHPoint {
	
    public double x, y;


    public CHPoint(double x, double y) {
        this.x=x;
        this.y=y;
    }

    public CHPoint(CHPoint p) {
        this(p.x, p.y);
    }

    public CHPoint relTo(CHPoint p) {
        return new CHPoint(x-p.x, y-p.y);
    }

    public CHPoint moved(double x0, double y0) {
        return new CHPoint(x+x0, y+y0);
    }

    public boolean isLower(CHPoint p) {
        return y<p.y || y==p.y && x<p.x;
    }

    public double mdist() {   // Manhattan-Distanz 
        return Math.abs(x)+Math.abs(y);
    }

    public double mdist(CHPoint p) {
        return relTo(p).mdist();
    }


    public boolean isFurther(CHPoint p) {
        return mdist()>p.mdist();
    }

    public boolean isBetween(CHPoint p0, CHPoint p1) {
        return p0.mdist(p1)>=mdist(p0)+mdist(p1);
    }
    
    public double cross(CHPoint p) {
        return x*p.y-p.x*y;
    }
    
    public boolean isLess(CHPoint p) {
        double f=cross(p);
        return f>0 || f==0 && isFurther(p);
    }

    public double area2(CHPoint p0, CHPoint p1) {
        return p0.relTo(this).cross(p1.relTo(this));
    }
    
    public String toString() {
    	return "x:" + x + " " + "y:" + y;
    }

}
